<?php
//App::uses('AppModel', 'Model');
App::uses('AppModel', 'Model', 'AuthComponent', 'Controller/Component');
/**
 * User Model
 *
 * @property Group $Group
 * @property User $User
 */
class User extends AppModel {
    public $displayField = 'username';
    public $belongsTo = array(
            'Group' => array(
                    'className' => 'Group',
                    'foreignKey' => 'group_id',
                    'conditions' => '',
                    'fields' => '',
                    'order' => ''
            )
    );

    public $hasMany = array(
            'User' => array(
                    'className' => 'User',
                    'foreignKey' => 'id_user',
                    'dependent' => false,
                    'conditions' => '',
                    'fields' => '',
                    'order' => '',
                    'limit' => '',
                    'offset' => '',
                    'exclusive' => '',
                    'finderQuery' => '',
                    'counterQuery' => ''
            )
    );	
	
    public $actsAs = array('Acl' => array('type' => 'requester'));

    public function parentNode() {
             if (!$this->id && empty($this->data)) {
                 return null;
             }
             if (isset($this->data['User']['group_id'])) {
                 $groupId = $this->data['User']['group_id'];
             } else {
                 $groupId = $this->field('group_id');
             }
             if (!$groupId) {
                 return null;
             } else {
                 return array('Group' => array('id' => $groupId));
             }
    }
    public function bindNode($user) {
   		return array('model' => 'Group', 'foreign_key' => $user['User']['group_id']);
    }


}
